<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">会员订单表</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!home">首页</a>
          <a><cite>会员订单表</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
                      搜索：  <select id="order-search-key">
            <option value="">-请选择-</option>
                 <!--<option value="id">ID</option>-->
                 <option value="order_no">订单编号</option>
                 <!--<option value="business_id">商家ID</option>-->
                 <!--<option value="member_id">会员ID</option>-->
                 <!--<option value="status">订单状态 -1-已取消,-2-申请退款，-3-已退款，0-待付款,1-服务中，2-待评价，3-已完成</option>-->
                 <!--<option value="service_type">订单类型，1-咨询订单，2-闪测订单，3-提问订单，4-充值订单</option>-->
                 <!--<option value="teacher_id">大师ID</option>-->
                 <!--<option value="total_amount">订单金额</option>-->
                 <!--<option value="create_date">下单时间</option>-->
                 </select>&emsp;
            <input id="order-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="order-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <table class="layui-table" id="order-table" lay-filter="order-table"></table>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="order-table-bar">
 {{#   if(admin.hasPerm("order:order:update") ){   }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
 {{#     } }} 
 <!--{{#  if(admin.hasPerm("order:order:delete") ){   }}-->
    <!--<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>-->
 <!--{{#     } }} -->
</script>


<script type="text/html" id="toolbar">
     {{#  if(admin.hasPerm("order:order:save")){ }}
     <button id="order-btn-add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
     {{#     } }} 
 
</script>

<script type="text/html" id="strstatus">
    {{#   if(d.status==-1){   }}
    <label class="layui-form-label">已取消</label>
    {{#     } }}
    {{#   if(d.status==-2){   }}
    <label class="layui-form-label">申请退款</label>
    {{#     } }}
    {{#   if(d.status==-3){   }}
    <label class="layui-form-label">已退款</label>
    {{#     } }}
    {{#   if(d.status==0){   }}
    <label class="layui-form-label">待付款</label>
    {{#     } }}
    {{#   if(d.status==1){   }}
    <label class="layui-form-label">服务中</label>
    {{#     } }}
    {{#   if(d.status==2){   }}
    <label class="layui-form-label">待评价</label>
    {{#     } }}
    {{#   if(d.status==3){   }}
    <label class="layui-form-label">已完成</label>
    {{#     } }}
</script>

<script type="text/html" id="strservicetype">
    {{#   if(d.serviceType==1){   }}
    <label class="layui-form-label">咨询订单</label>
    {{#     } }}
    {{#   if(d.serviceType==2){   }}
    <label class="layui-form-label">闪测订单</label>
    {{#     } }}
    {{#   if(d.serviceType==3){   }}
    <label class="layui-form-label">提问订单</label>
    {{#     } }}
    {{#   if(d.serviceType==4){   }}
    <label class="layui-form-label">充值订单</label>
    {{#     } }}
    {{#   if(d.serviceType==5){   }}
    <label class="layui-form-label">会员认证</label>
    {{#     } }}
</script>

<script>
   var admin;
    layui.use(['form', 'table', 'util', 'config', 'admin', 'upload','laytpl','element' ], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
          admin = layui.admin;
        //上传
        var upload = layui.upload;
        let laytpl = layui.laytpl;
        let element = layui.element;

        // 渲染表格
        table.render({
            elem: '#order-table',
            url: config.base_server + 'order/order/list',
            method: 'GET',
       
            page: true,
            cols: [[
                {type: 'numbers'},
                           // {field: 'id', sort: true, title: 'ID'},
                           {field: 'orderNo',  title: '订单编号'},
                           {field: 'businessName',  title: '商家名称'},
                           {field: 'memberName',  title: '会员名称'},
                           {field: 'status',  title: '订单状态',toolbar:"#strstatus"},
                           {field: 'serviceType',  title: '订单类型',toolbar:"#strservicetype"},
                           {field: 'teacherName',  title: '大师名称'},
                           {field: 'totalAmount',  title: '订单金额', templet: function (d) {
                                   return '¥ '+(d.totalAmount||0);
                               }
                           },
                           {field: 'createDate',  title: '下单时间'},
                        
                {fixed: 'right', align: 'center', toolbar: '#order-table-bar', title: '操作', width: 175}
            ]]
        });
        
        laytpl($("#toolbar")[0].innerHTML).render({ }, function(html){
			  $(".layui-card-body .toolbar").append(html);
			  element.render('nav');
		  });

        // 添加按钮点击事件
        $('#order-btn-add').click(function () {
            showEditModel();
        });

        // 工具条点击事件
        table.on('tool(order-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'edit') { // 修改
             
                showEditModel(data);
            }  else if (layEvent === 'del') { // 删除
                layer.confirm('确定删除吗？', function (i) {
                    layer.close(i);
                    layer.load(2);
                    // admin.req('order/order/delete/'+obj.data.id, {}, function (data) {
                    //     layer.closeAll('loading');
                    //     if (data.code == 0) {
                    //         layer.msg(data.msg, {icon: 1, time: 500});
                    //         table.reload('order-table', {});
                    //     } else {
                    //         layer.msg(data.msg, {icon: 2, time: 500});
                    //     }
                    // }, 'delete');
                });
            }
        });

        //显示表单弹窗
        var showEditModel = function (data) {
        	  var title = data ? '修改用户' : '添加用户';
            //修改方法名
            if (data){
                data.method="update"
            }else{
            	data={method:"save"};
            }
 
            admin.putTempData('t_order', data);
            admin.popupCenter({
                title: title,
                path: 'pages/order/order_form.html',
                finish: function () {
                    table.reload('order-table', {});
                }
            });
        };

        // 搜索按钮点击事件
        $('#order-btn-search').click(function () {
            var key = $('#order-search-key').val();
            var value = $('#order-search-value').val();
            table.reload('order-table', {where: {searchKey: key, searchValue: value}});
        });

    });
</script>
